package config_order.config;

import config_order.bean.Bean1;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;

/**
 * 描述：
 *
 * @import + ImportBeanDefinitionRegistrar 可以实现配置自动引用 不需要@Compoent
 *
 * @author 🧑 ‍wanwei
 * @since 2022-10-14 11:29
 */
//@Component
public class ImportBeanDefinitionRegistrarDemo implements ImportBeanDefinitionRegistrar {


	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		System.out.println("自定义添加bean");
		System.out.println(importingClassMetadata);
		System.out.println(registry);
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Bean1.class);
		builder.addPropertyValue("name","1");
		builder.addPropertyValue("age","2");
		builder.addPropertyValue("type","3");
		registry.registerBeanDefinition("myselfRegistryBean1",builder.getBeanDefinition());
	}
}
